<div class="container">

    <div class="page-header">
        <div class="row">
            <h1 class="span8">View All Documents</h1>
            <span class="span4 clearfix">
                <a class="nav-control new-page w-18" href="<?= base_url('documents/view_new?post_type=document') ?>">
                    Add Folders / Files
                </a>
            </span>
        </div>


    </div>

    <div class="row">

        <div class="span12">

            <table class="table table-striped table-bordered table-condensed">
                <thead>
                    <tr>
                        <th>Folder</th>
                        <th>Link to</th>
                        <th>Files</th>
                        <th class="th-action center">Action</th>
                    </tr>
                </thead>
                <tbody>
                    
                    <?
                    $_GET['_cur_level'] = 0;

                    function parents_finder ($parent_ID = 0, $page_type){

                    $CI = & get_instance ();

                    $galleries = $CI->document_model->view_all_children($parent_ID, $page_type);
                    foreach ($galleries as $oneGallery):

                    $cur_ID = $oneGallery['ID'];

                    if ($oneGallery['posts_ID'] != NULL)
                    $page = $CI->translate->asoc_array($CI->posts_model->view_edit($oneGallery['posts_ID']), $CI->activeLang);
                    ?>
                    <tr>
                        <td><a href="<?= base_url('documents/view_edit?documents_ID=' . $cur_ID . '&post_type=documents') ?>"><?= repeat_sign('&nbsp;', $_GET['_cur_level'] * 3) . '- ' . $oneGallery['title'] ?></a></td>
                        <td><?= $oneGallery['posts_ID'] != NULL ? $page['post_title'] : 'Not linked' ?></td>
                        <td><?= $oneGallery['file_count'] ?></td>
                        <td class="center">
                            <a href="<?= base_url() ?>documents/view_edit?documents_ID=<?= $cur_ID ?>&post_type=documents"><i class="icon-pencil"></i> Edit</a> |
                            <a href="<?= base_url() ?>documents/delete/<?= $cur_ID ?>?post_type=documents" class="delete_post"><i class="icon-trash"></i> Delete</a>
                        </td> 
                    </tr>

                    <?

                    if (count($CI->document_model->view_all_children($oneGallery['ID'],$page_type)) > 0) :
                    $_GET['_cur_level'] +=1;
                    parents_finder($cur_ID, $page_type);
                    endif;

                    endforeach;

                    $_GET['_cur_level'] --;

                    }

                    ?>


                    <?foreach (config_item('page_types') as $page_type):?>
                    <tr><td colspan="5"><strong><?= ucfirst($page_type) ?></td> </tr>
                    <?
                    parents_finder(0, $page_type); 
                    endforeach;
                    unset($_GET['_cur_level']); 
                    ?>
                    
                </tbody>
            </table>

        </div>

    </div>

</div> <!-- /container -->